package com.application.sistercityapplication.main;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageView;

import com.application.sistercityapplication.listadapter.GridViewImageAdapter;
import com.roscopeco.ormdroid.ORMDroidApplication;

public class NewMainPageMainActivity extends Activity {
	private GridView gridView;
	private int columnWidth;
	private Utils utils;
	private ImageView settingBtn ;
	private GridViewImageAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
		ORMDroidApplication.initialize(NewMainPageMainActivity.this);
		setContentView(R.layout.activity_new_main_page_main);	
		settingBtn = (ImageView) findViewById(R.id.imageView1);
		gridView = (GridView) findViewById(R.id.grid_view);
		utils = new Utils(getApplicationContext());
		InitilizeGridLayout();

		List<Integer> inn = new ArrayList<Integer>();
		for(int i=0;i<10;i++){
			inn.add(i);
		}
		adapter = new GridViewImageAdapter(this,inn,columnWidth);
		gridView.setAdapter(adapter);
		
		settingBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(NewMainPageMainActivity.this,MainSettingPageViewActivity.class);
				startActivity(i);
			}
		});
	}
	private void InitilizeGridLayout() {
		Resources r = getResources();
		float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,AppConstant.GRID_PADDING, r.getDisplayMetrics());

		columnWidth = (int) ((utils.getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);

		gridView.setNumColumns(AppConstant.NUM_OF_COLUMNS);
		gridView.setColumnWidth(columnWidth);
		gridView.setStretchMode(GridView.NO_STRETCH);
		gridView.setPadding((int) padding, (int) padding, (int) padding,(int) padding);
		gridView.setHorizontalSpacing((int) padding);
		gridView.setVerticalSpacing((int) padding);
	}
	public class AppConstant {

		// Number of columns of Grid View
		public static final int NUM_OF_COLUMNS = 3;

		// Gridview image padding
		public static final int GRID_PADDING = 20; // in dp

		// SD card image directory
		public static final String PHOTO_ALBUM = "NAT";

		// supported file formats
		public final List<String> FILE_EXTN = Arrays.asList("jpg", "jpeg","png");
	}
}
